package GUI;
/*  
 * Christopher Deckers (chrriis@nextencia.net)  
 * http://www.nextencia.net  
 *  
 * See the file "readme.txt" for information on usage and redistribution of  
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.  
 */  
import java.awt.BorderLayout;   
import java.awt.FlowLayout;   
import java.awt.event.ItemEvent;   
import java.awt.event.ItemListener;   
  
import javax.swing.BorderFactory;   
import javax.swing.JCheckBox;   
import javax.swing.JFrame;   
import javax.swing.JPanel;   
import javax.swing.SwingUtilities;   
  
import chrriis.common.UIUtils;   
import chrriis.dj.nativeswing.swtimpl.NativeInterface;   
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser; 
   
public class WebBrowserPanel extends JPanel {   
  
  public WebBrowserPanel(String url) {   
    super(new BorderLayout());   
    JPanel webBrowserPanel = new JPanel(new BorderLayout());   
    webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Trailer"));   
    final JWebBrowser webBrowser = new JWebBrowser();  
    //webBrowser.navigate(url); 
    String htmlcontent = "<object width=\"475\" height=\"290\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"> <param name=\"movie\" value=\"http://www.player.filmtrailer.com/v3.5/player.swf?display_title=none&default_quality=xlarge&autostart=true&share=1&logo=0&backcolor=241D16&frontcolor=7F7F7F&freemium=1&motd=1 \"/> <param name=\"FlashVars\" value=\"file=http://de.player-feed.previewnetworks.com/v3.1/cinema/2981/491100000-1/\" /> <param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /> <embed type=\"application/x-shockwave-flash\" src=\"http://www.player.filmtrailer.com/v3.5/player.swf?display_title=none&default_quality=xlarge&autostart=true&share=1&logo=0&backcolor=241D16&frontcolor=7F7F7F&freemium=1&motd=1\" FlashVars=\"file=http://de.player-feed.previewnetworks.com/v3.1/cinema/2981/491100000-1/\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"475\" height=\"290\"></embed> </object>"; 
    htmlcontent += "<br/> <a style=\"font-family: verdana; color:cccccc; font-size: 8pt; text-decoration:none\" alt=\"filmtrailer.com\" target=\"_blank\" href=\"http://de.filmtrailer.com/\">Kinotrailer von Filmtrailer.com</a>";
    webBrowser.setHTMLContent(htmlcontent);
    webBrowser.setBarsVisible(false);    
    webBrowserPanel.add(webBrowser, BorderLayout.CENTER);   
    add(webBrowserPanel, BorderLayout.CENTER);   
    // Create an additional bar allowing to show/hide the menu bar of the web browser.   
/*    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));   
    JCheckBox menuBarCheckBox = new JCheckBox("Menu Bar", webBrowser.isMenuBarVisible());   
    menuBarCheckBox.addItemListener(new ItemListener() {   
      public void itemStateChanged(ItemEvent e) {   
        webBrowser.setMenuBarVisible(e.getStateChange() == ItemEvent.SELECTED);   
      }   
    });   
    buttonPanel.add(menuBarCheckBox);   
    add(buttonPanel, BorderLayout.SOUTH); */  
  }    
  
  public static void startWebBrowser(final String url)
  {
	  UIUtils.setPreferredLookAndFeel();   
	    if(!NativeInterface.isOpen())
	    	NativeInterface.open();  
	    	    SwingUtilities.invokeLater(new Runnable() {   
	      public void run() {   
	        JFrame frame = new JFrame("Kino-WebBrowser");   
	        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);  
	        frame.pack();
	        frame.getContentPane().add(new WebBrowserPanel(url), BorderLayout.CENTER);   
	        frame.setSize(800, 600);   
	        frame.setLocationByPlatform(true);   
	        frame.setVisible(true);   
	      }   
	    });   	    
	    if(!NativeInterface.isOpen())
	    	NativeInterface.runEventPump();   
  }
}  